package cn.glutnn.subject.domain.handler.subject;

import cn.glutnn.subject.common.enums.IsDeletedFlagEnum;
import cn.glutnn.subject.common.enums.SubjectInfoTypeEnum;
import cn.glutnn.subject.domain.convert.SubjectBriefConverter;
import cn.glutnn.subject.domain.enyity.SubjectInfoBO;
import cn.glutnn.subject.domain.enyity.SubjectOptionBO;
import cn.glutnn.subject.infra.basic.entity.SubjectBrief;
import cn.glutnn.subject.infra.basic.service.SubjectBriefService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * Author:   msh
 * Date:     2024/11/28 下午3:12
 * Description: 简答题的策略类
 */

@Component
public class BriefTypeHandler implements SubjectTypeHandler {
    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = SubjectBriefConverter.INSTANCE.convertBoToSubjectBrief(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectBriefService.save(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        SubjectBrief subjectBrief = subjectBriefService.getById(subjectId);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectOptionBO;
    }
}
